import collections
class Solution(object):
    def shareCandies(self, candies, k):
        d = collections.Counter(candies)
        for i in range(k):
            d[candies[i]] -= 1
            if not d[candies[i]]:
                d.pop(candies[i])
        max_len = len(d)
        for i in range(len(candies) - k):
            d[candies[i]] += 1
            d[candies[i + k]] -= 1
            if not d[candies[i + k]]:
                d.pop(candies[i + k])
            max_len = max(max_len, len(d))
        return max_len